s = "   fly me   to   the moon  "
var lengthOfLastWord = function(s) {
    let n = s.length-1
    while(s[n]===" "){
        n--
    }
    let end = n
    while(s[n]!==" "){
        n--
    }
    let start = n
    return end-start
}

console.log(lengthOfLastWord(s));
